import {
    specsList,
    specsCount,
    specsInfo
} from "../../request/api"

const state = {
    specsList: [],
    specsCount: "",
    specsInfo:{},
}
//导出
const getters = {
    specsList(state) {
        return state.specsList
    },
    specsCount(state) {
        return state.specsCount
    },
    specsInfo(state) {
        return state.specsInfo
    },
}
//修改
const mutations = {
    cSpecsList(state, data) {
        state.specsList = data;
    },
    cSpecsCount(state, data) {
        state.specsCount = data;
    },
    cSpecsInfo(state, data) {
        state.specsInfo = data;
    },
}
// 异步逻辑
const actions = {
    reqSpecsList(context, data) {
        specsList(data).then(res => {
            context.commit("cSpecsList", res.data.list)
        })
    },
    reqSpecsCount(context) {
        specsCount().then(res => {
            context.commit("cSpecsCount", res.data.list[0].total)
        })
    },
    reqSpecsInfo(context,data) {
        specsInfo({id:data}).then(res => {
            context.commit("cSpecsInfo", res.data.list[0])
        })
    },
}

export default {
    state,
    getters,
    mutations,
    actions,
    namespaced: true
}